package com.luxiu.extensionlib.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.luxiu.extensionlib.R

/**
var adapter=VariousSpinnerAdapter(
    this,
    arrayOf("aaa",
        "111",
        "222")
)
adapter.mTextSize=18f
mBinding.spinner.adapter =adapter
 */
class VariousSpinnerAdapter(
    context: Context,
    objects: Array<String>,
) : AbstractSpinnerAdapter<String>(context, 0, objects) {

    var mTextSize = 14f

    override fun initDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
        return createCommonView(position, convertView, parent)
    }

    override fun initDefaultView(position: Int, convertView: View?, parent: ViewGroup): View {
        return createCommonView(position, convertView, parent)
    }

    private fun createCommonView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = convertView ?: LayoutInflater.from(context).inflate(
            R.layout.default_spinner_item,
            parent,
            false
        )
        val textView = view.findViewById<TextView>(R.id.mText)
        textView.text = getItem(position)
        textView.textSize = mTextSize
        return view
    }
}